import { useEffect, useState } from 'react'
import { getChannelAPI } from '@/apis/article'

const useChannel = () => {
  // ##### 频道列表相关 #####
    const [channelList, setChannelList] = useState([])
    useEffect(() => {
      // 获取
      const fetchChannelList = async () => {
        const res = await getChannelAPI()
        setChannelList(res.data.channels)
      }
      fetchChannelList()
    }, [])
    // 遍历渲染
    const options = channelList.map(item => ({
      value: item.id, /* value属性用户选中之后会自动收集起来作为接口的提交字段 */
      label: item.name,
    }));
    return {
       options
    }
}

export { useChannel }